package com.wanlian.router.ui.integral;

import android.content.Context;
import android.text.SpannableString;
import android.text.style.RelativeSizeSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.smart.android.image.ImageLoader;
import com.smart.android.ui.tools.MyNiuBAdapter;
import com.wanlian.router.R;
import com.wanlian.router.bean.TelecomRechargeCard;

import java.util.List;
import java.util.Locale;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Hyu on 2018/9/23.
 * Email: fvaryu@163.com
 */
public class TelecomCardAdapter extends MyNiuBAdapter<TelecomRechargeCard>{

    public TelecomCardAdapter(Context context, List<TelecomRechargeCard> mTs) {
        super(context, mTs);
    }

    @Override
    public int layout() {
        return R.layout.layout_item_telecom_card;
    }

    @Override
    public MyViewHolder<TelecomRechargeCard> holder(View view) {
        return new TC(view);
    }

    class TC extends MyViewHolder<TelecomRechargeCard> {

        @BindView(R.id.tv_amount)
        TextView tv_amount;
        @BindView(R.id.tv_account)
        TextView tv_account;
        @BindView(R.id.tv_pwd)
        TextView tvpwd;
        @BindView(R.id.image_logo)
        ImageView mImageView;

        public TC(View view) {
            super(view);
        }

        @Override
        public void setData(int i, TelecomRechargeCard telecomRechargeCard) {
            ImageLoader.load(mImageView.getContext(), telecomRechargeCard.getImgPath(), mImageView);

            SpannableString ss = new SpannableString(String.format(Locale.getDefault(), "¥%d", telecomRechargeCard.getRmb()));
            ss.setSpan(new RelativeSizeSpan(0.6f), 0, 1, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
            tv_amount.setText(ss);
            tv_account.setText(String.format("卡号 %s", telecomRechargeCard.getUICode()));
            tvpwd.setText(String.format("密码 %s", telecomRechargeCard.isShowPWD() ? telecomRechargeCard.getUIPWD() : telecomRechargeCard.getUIHiddenPWD()));

            tvpwd.setCompoundDrawablesWithIntrinsicBounds(0, 0, telecomRechargeCard.isShowPWD() ? R.drawable.eye_open
                    : R.drawable.eye_close, 0);
            tvpwd.setTag(telecomRechargeCard);
        }

        @OnClick(R.id.tv_pwd)
        void pwd(View v) {
            TelecomRechargeCard telecomRechargeCard = (TelecomRechargeCard) v.getTag();
            telecomRechargeCard.setShowPWD(!telecomRechargeCard.isShowPWD());
            notifyDataSetChanged();

        }
    }
}
